package com.tianqi.familymap.entry

import android.app.Application
import android.content.Context
import com.facebook.stetho.Stetho
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.FormatStrategy
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import com.tianqi.familymap.utils.ContantUtils
import com.tianqi.familymap.utils.OkHttpUtils
import com.tianqi.familymap.utils.SPUtils
import okhttp3.OkHttpClient

class MyApp : Application() {

    companion object{
        //获取okHtpClient，使用log拦截器
        val okHtpClient: OkHttpClient = OkHttpUtils.getTianqi("tianqi").getOkHttpClient();

        private var instance:MyApp? = null
            get() {
                if (field == null)
                    field = MyApp()
                return field
            }
        fun get():MyApp{
            return instance!!
        }
    }

    override fun onCreate() {
        super.onCreate()
        initConfig()
    }

    private fun initConfig(){
        ContantUtils.setCompositeDisposable()//获取网络请求订阅器
        //初始化FaceBook调试器,可在Chrome调试网络请求,查看SharePreferences,数据库等
        Stetho.initializeWithDefaults(this);
        // 打印设置
        val formatStrategy: FormatStrategy = PrettyFormatStrategy.newBuilder()
            .tag("Family_Map")
            .build()
        Logger.addLogAdapter(AndroidLogAdapter(formatStrategy))
//        SPUtils.put(applicationContext,"token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpc3MiLCJhdWQiOiJhdWQiLCJqdGkiOiI2MmMwYTA5NzFlMjkzYTZmZTc1YTk2ZjgyNzQwNDlmMCIsImlhdCI6MTYwMTk0Njg0MCwibmJmIjoxNjAxOTQ2ODQwLCJleHAiOjE2NzM5NDY4NDAsInVpZCI6MjU1fQ.UciHS5VYING0K87zUkuQCRar_e4AC6_sAGf5RDIYk78")
    }
}